Q1: Today, we used two variables in a for-loop. Is it also possible to iterate using three or more variables?
A: Yes. You have to use as many variables as there are items in the internal tuples or lists. In the example below, we iterate using three variables:
buttons = [('John', 'Sen', 'Morro'), ('Lin', 'Ajay', 'Filip')]
for first, second, third in buttons:
print(first, second, third)Note that the enumerate function always produces a sequence of tuples each containing two items. Therefore, when using enumerate, you have to use two variables, not less, not more.
Q2: Is an f-string always used in conjunction with a for loop?
A: No. f-strings can be used independently. For example:
name = input("Enter your name: ")
print(f"Your name is {name}.")Here is the output of that:
